package com.wisdytech.linkdcs.account.service.impl;

import com.wisdytech.linkdcs.account.model.Property;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.constants.CommonConstants;
import com.wisdytech.common.handler.BaseService;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.account.dao.PropertyDao;
import com.wisdytech.linkdcs.account.service.IPropertyService;
import com.wisdytech.linkdcs.factory.dao.TmFactoryDao;
import com.wisdytech.linkdcs.factory.model.Factory;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenbin
 * @since 2018-07-19
 */
@Service("iPropertyService")
@Transactional
public class PropertyServiceImpl extends BaseService<PropertyDao, Property> implements IPropertyService {

	@Resource
	private PropertyDao propertyDao;
	
	@Override
	public void addProperty(Property property, String loginName) {
		property.setPkId(BaseUtil.getUUID());
		property.setDelFalg(CommonConstants.DEL_FLAG);
		propertyDao.insert(property);
	}

	@Override
	public PageInfo<Property> listPropertyByFilter(Filter filter) {
		EntityWrapper<Property> ew = new EntityWrapper<>();
		List<Property> list = super.beforeList(PropertyDao.class, filter)
                .selectList(ew.eq("DEL_FLAG", CommonConstants.DEL_FLAG));
        PageInfo<Property> page = new PageInfo<>(list);
        return page;
	}

	@Override
	public Property getPropertyById(String pkId) {
		Property property = new Property();
		property.setPkId(pkId);
		return propertyDao.selectOne(property);
	}

	@Override
	public void updateProperty(Property property, String loginName) {
		propertyDao.updateById(property);
	}

	@Override
	public void delPropertyById(String pkIds) {
        List<String> idList = new ArrayList<String>();
        String[] id = pkIds.split(",");
        for (int i = 0; i < id.length; i++) {
            idList.add(id[i]);
        }
        propertyDao.deleteBatchIds(idList);
		
	}

	@Override
	public List<Property> listPropertyAll() {
		EntityWrapper<Property> ew = new EntityWrapper<>();
		ew.eq("DEL_FLAG", CommonConstants.DEL_FLAG);
		return propertyDao.selectList(ew);
	}

}
